import { observer } from "mobx-react";
import { toJS } from 'mobx';
import D3Tree from "../../common/tree/RectTree";
import {WeaLocaleProvider} from "ecCom";
const getLabel = WeaLocaleProvider.getLabel;
import { TaskViewPageType } from "../../../constants/task";
import { message } from 'antd';
import routes from "../../../constants/route";

@observer
export default class DataPath extends React.Component {
    render() {
        const { store } = this.props;
        return (
            <div className="edc-data-path">
                {store.noPath ? <div style={{ fontSize: 16, paddingTop: 100, textAlign: 'center', color: '#ccc' }} >
                    {getLabel('502289','请在左侧选择上报任务') }
                </div> :
                    <D3Tree ecId={`${this && this.props && this.props.ecId || ''}_D3Tree@u4mi2d`}
                        data={toJS(store.pathNode)}
                        onClickTitle={this.openNode}
                        widthToggle={false}
                        showRight={false}
                        desc="submitDate"
                        showname={this.getShowname}
                        nameTitle={getLabel('506148','点击查看数据')}
                        showOperator={true}
                        showHreflink={true}
                        isSplit={store.isPathSplit}
                    />
                }
            </div>
        )
    }
    
    getShowname = (d) => {
        return `${d.name}`;
    }

    openNode = (d) => {
        const { hreflinkObj = [], formData = '' } = d || {};
        const [type, hreflink, pageid] = hreflinkObj;
        if (type === TaskViewPageType.EXCEL && pageid) {
            if(!formData) {
                message.warn(getLabel('511551','该节点没有上传数据，无法查看！'));
                return;
            }
            window.open(`#/${routes.excelView}?nodeid=${d.id}&pageid=${pageid}&dataid=${formData}`)
            //window.open(`${ViewUrl}#/${routes.excelView}?pageid=${pageid}&dataid=${formData}`);
        } else if (type === TaskViewPageType.FORM && pageid && formData) {
            window.open(`${ViewUrl}#/${routes.form}/${pageid}?dataid=${formData}`);
        }

    }
}